< Prev(J) / Next(K) > / View :

Filename: /text/sbasic/shared/03100100.xhp

(section: cbool) (bookmark: bm_id3150616)
CBool function

CBool 関数

CBool Function [Runtime]
CBool 関数 [実行時](hd_id3150616.1)

Converts a string comparison or numeric comparison to a Boolean expression, or converts a single numeric expression to a Boolean expression.
文字列や数値の比較演算結果、および単独の数値表式をブール型の表式に変換します。(par_id3145136.2)

(/section: cbool)

Syntax:
構文:(hd_id3153345.3)

CBool (Expression1 {= | <> | < | > | <= | >=} Expression2) or CBool (Number)
CBool (Expression1 {= | <> | < | > | <= | >=} Expression2) あるいは CBool (Number)(par_id3149514.4)

Return value:
戻り値:(hd_id3156152.5)

Bool
ブール型(par_id3155419.6)

Parameters:
パラメータ:(hd_id3147530.7)

Expression1, Expression2: Any string or numeric expressions that you want to compare. If the expressions match, the CBool function returns True, otherwise False is returned.
Expression1, Expression2: 比較する文字列および数値の表式。CBool 関数は、2 つの表式が一致すれば True を返し、それ以外の場合は False を返します。(par_id3156344.8)

Number: Any numeric expression that you want to convert. If the expression equals 0, False is returned, otherwise True is returned.
Number: 変換させる数値表式。表式が 0 に等しい場合は False を返し、それ以外の場合は True を返します。(par_id3149655.9)

The following example uses the CBool function to evaluate the value that is returned by the Instr function. The function checks if the word "and" is found in the sentence that was entered by the user.
下記の例は、Instr 関数から返される値を、CBool 関数を使って評価させています。この関数は、ユーザーの入力する文字列の中に「and」という単語が含まれているかを判定します。(par_id3145171.10)

(embed text/sbasic/shared/00000003.xhp#errorcode : linkinfo)

Error Codes

エラーコード(hd_id3152869.37)

(/embed text/sbasic/shared/00000003.xhp#errorcode)

(embed text/sbasic/shared/00000003.xhp#err5 : linkinfo)

5 Invalid procedure call
5 無効なプロシージャー呼び出しです (par_id3150891.41)

(/embed text/sbasic/shared/00000003.xhp#err5)

Example:
例:(hd_id3156212.11)

Sub ExampleCBool
Sub ExampleCBool(par_id3147288.12)

Dim sText As String
Dim sText As String(par_id3153768.13)

sText = InputBox("Please enter a short sentence:")
sText = InputBox("Please enter a short sentence:")(par_id3155132.14)

REM Proof if the word »and« appears in the sentence.
REM 入力した文字列中に「and」があるかを調べます。(par_id3155855.15)

REM Instead of the command line
REM 通常こうした判定には下記のような IF 文を使います。(par_id3146984.16)

REM If Instr(Input, "and")<>0 Then...
REM If Instr(Input, "and")<>0 Then...(par_id3148576.17)

REM the CBool function is applied as follows:
REM ここではその代わりに CBool 関数を使って判定をしています。(par_id3154014.18)

If CBool(Instr(sText, "and")) Then
If CBool(Instr(sText, "and")) Then(par_id3155413.19)

MsgBox "The word »and« appears in the sentence you entered!"
MsgBox "入力した文字列中に「and」があります。(par_id3152940.20)

EndIf
EndIf(par_id3153954.21)

End Sub
End Sub(par_id3152886.22)


< Prev / Next >